有一款微信小程序游戏,“最强连一连”,本工程用于对该游戏进行解密,按照提示将游戏信息输入本程序,本程序将会自动计算路线。朋友推荐了这款游戏,挺好玩了,既能锻炼智力又能打发时间,但是本人又不想动脑,所以开发了这款解密程序。说笑,其实我也是新手,正好看到朋友玩这款游戏玩的焦头烂额的,我正好想学习GUI编程,拿这个练习GUI编程罢了。使用的python版本为3.6.5,使用的GUI模块为wxpython。本人在此实例下提供的实例文件,包含源代码文件lianyilian_my.py,程序所用素材文件(file文件夹及其中文件),以及一个用pyinstaller打包生成的exe程序,无需安装python即可直接在windows系统运行(zip压缩包,解压后找到lianyilian_my.exe双击即可运行)解密方法就是递归算法,傻瓜式的一个一个试class BitmapButtonFrame(wx.Frame): def __init__(self):
self.bmp_fangkuai = wx.Bitmap('./file/fangkuai.bmp', wx.BITMAP_TYPE_BMP)
self.bmp_kongbai = wx.Bitmap('./file/kongbai.bmp', wx.BITMAP_TYPE_BMP)
self.bmp_start = wx.Bitmap('./file/start.bmp', wx.BITMAP_TYPE_BMP)
self.bmp_start2shang = wx.Bitmap('./file/start2shang.bmp', wx.BITMAP_TYPE_BMP)
self.bmp_start2xia = wx.Bitmap('./file/start2xia.bmp', wx.BITMAP_TYPE_BMP)
self.bmp_start2zuo = wx.Bitmap('./file/start2zuo.bmp', wx.BITMAP_TYPE_BMP)
self.bmp_start2you = wx.Bitmap('./file/start2you.bmp', wx.BITMAP_TYPE_BMP)
self.bmp_shang_xia = wx.Bitmap('./file/shang_xia.bmp', wx.BITMAP_TYPE_BMP)
self.bmp_zuo_you = wx.Bitmap('./file/zuo_you.bmp', wx.BITMAP_TYPE_BMP)
self.bmp_zuo_shang = wx.Bitmap('./file/zuo_shang.bmp', wx.BITMAP_TYPE_BMP)
self.bmp_zuo_xia = wx.Bitmap('./file/zuo_xia.bmp', wx.BITMAP_TYPE_BMP)
self.bmp_you_shang = wx.Bitmap('./file/you_shang.bmp', wx.BITMAP_TYPE_BMP)
self.bmp_you_xia = wx.Bitmap('./file/you_xia.bmp', wx.BITMAP_TYPE_BMP)
self.bmp_shang2stop = wx.Bitmap('./file/shang2stop.bmp', wx.BITMAP_TYPE_BMP)
self.bmp_xia2stop = wx.Bitmap('./file/xia2stop.bmp', wx.BITMAP_TYPE_BMP)
self.bmp_zuo2stop = wx.Bitmap('./file/zuo2stop.bmp', wx.BITMAP_TYPE_BMP)
self.bmp_you2stop = wx.Bitmap('./file/you2stop.bmp', wx.BITMAP_TYPE_BMP)
[self.width, self.height] = get_size()
# print(self.width, self.height)
self.w_1, self.h_1 = self.width*50 16, self.height*50 115
# print(self.w_1, self.h_1)
wx.Frame.__init__(self, None, -1, "连一连解密", size=(self.w_1, self.h_1))
self.panel = wx.Panel(self, -1)
self.my_progress = 0
self.button_pos = {}
self.start_pos = 0, 0
self.step_count = self.width*self.height
self.map_data = []
# print(self.map_data)
self.names = locals()
for i in range(self.height):
self.map_data.append([])
for j in range(self.width):
self.map_data[i].append(1)
# print(self.map_data)
for i in range(self.height):
for j in range(self.width):
self.w_2, self.h_2 = j*50, i*50
# print(w_2, h_2)
self.names["button" str(i*self.width j)] = wx.BitmapButton(self.panel, -1,
self.bmp_fangkuai,
pos=(self.w_2, self.h_2),
size=(50,50), style=0)
self.button_pos[(str(self.names["button" str(i*self.width j)])[-5:-1])] = i,j
self.Bind(wx.EVT_BUTTON, self.onclick, self.names["button" str(i*self.width j)])
# print(self.button_pos)
self.tishi_1 = wx.StaticText(self.panel, label="请依次点击墙的位置", pos=(5, 50 * self.height 5))
self.tishi_2 = wx.StaticText(self.panel, label="然后点击下一步", pos=(5, 50 * self.height 20))
self.button_next = wx.Button(self.panel, label="下一步", pos=(50*self.width-90, 50*self.height 40))
self.Bind(wx.EVT_BUTTON, self.click_next, self.button_next)
def onclick(self, event):
if self.my_progress == 0:
# print(event.GetEventObject())
i, j = self.button_pos[str(event.GetEventObject())[-5:-1]]
# print(i, j)
if self.map_data[i][j] != 0:
self.names["button" str(i * self.width j)].SetBitmap(self.bmp_kongbai)
self.map_data[i][j] = 0
self.step_count -= 1
# print(self.map_data)
elif self.my_progress == 1:
i, j = self.button_pos[str(event.GetEventObject())[-5:-1]]
# print(i, j)
self.names["button" str(i * self.width j)].SetBitmap(self.bmp_start)
self.map_data[i][j] = 7
# print(self.map_data)
self.start_pos = i, j
self.tishi_1.SetLabelText("路线计算中...")
ret = self.main_loop(self.map_data[:], self.start_pos, 1)
# print(ret)
if ret[0]:
self.show(ret[1])
self.tishi_1.SetLabelText("成功!")
else:
self.tishi_1.SetLabelText("输入错误!没有任何路线可以成功!")
self.button_next.SetLabel("重置")
self.my_progress = 2
def click_next(self, event):
if self.my_progress == 0:
self.my_progress = 1
self.tishi_1.SetLabelText("请点击起始位置")
self.tishi_2.SetLabelText("")
elif self.my_progress == 2:
self.my_init()
def my_init(self):
self.my_progress = 0
self.start_pos = 0, 0
self.step_count = self.width*self.height
# print(self.step_count)
for i in range(self.height):
for j in range(self.width):
self.map_data[i][j] = 1
# print(self.map_data)
for i in range(self.height):
for j in range(self.width):
self.names["button" str(i * self.width j)].SetBitmap(self.bmp_fangkuai)
# print(self.button_pos)
self.tishi_1.SetLabelText("请依次点击墙的位置")
self.tishi_2.SetLabelText("然后点击下一步")
self.button_next.SetLabel("下一步")
评论